// Definition for a binary tree node.
struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};
#include <queue>
using namespace std;
class BSTIterator
{
private:
    queue<int> que;
    void init_helper(TreeNode *root)
    {
        if (!root)
            return;
        init_helper(root->left);
        que.push(root->val);
        init_helper(root->right);
    }

public:
    BSTIterator(TreeNode *root)
    {
        init_helper(root);
    }
    int next()
    {
        int ret = que.front();
        que.pop();
        return ret;
    }

    bool hasNext()
    {
        return !que.empty();
    }
};

/**
 * Your BSTIterator object will be instantiated and called as such:
 * BSTIterator* obj = new BSTIterator(root);
 * int param_1 = obj->next();
 * bool param_2 = obj->hasNext();
 */